import Taro, { Component } from '@tarojs/taro'
import { View, Image, Text } from '@tarojs/components'
import { post } from '../../../service/api'
import './company.scss'

class Hcompany extends Component {
  constructor() {
    super(...arguments)
    this.state = {
      companyList: [],
      url: ['http://xlylf-hlj.oss-cn-hangzhou.aliyuncs.com/com/1111/usr/64c0cada311343f2ac7ee3ba35b11830.png',
        'http://xlylf-hlj.oss-cn-hangzhou.aliyuncs.com/com/1111/usr/f164cdb272b34034aa86dfcd26366352.png',
        'http://xlylf-hlj.oss-cn-hangzhou.aliyuncs.com/com/1111/usr/fc32aa5b6ac84c82946e758b4f8eb15b.png',
        'http://xlylf-hlj.oss-cn-hangzhou.aliyuncs.com/com/1111/usr/8f66c0d2ab9d44319ff8abfc6ae15b59.png',
        'http://xlylf-hlj.oss-cn-hangzhou.aliyuncs.com/com/1111/usr/9f9ff53a5632422392c2013b77265495.png',
        'http://xlylf-hlj.oss-cn-hangzhou.aliyuncs.com/com/1111/usr/891146f4113345c693af6e87290b6790.png']
    }
  }
  async getCompanyData() {
    const { data } = await post('home/findzxcompany')
    if (data.code == 0) {
      const companyList = data.rows.map((item, index) => {
        item.url = this.state.url[index];
        return item;
      })
      this.setState({
        companyList
      })
    }
  }
  toPageCompany() {
    Taro.switchTab({
      url: "/pages/company/index"
      // 加杠绝对路径
    })
  }
  toPageCompanyDetail(item) {
    Taro.navigateTo({ url: `/pages/companyDetail/index?id=${item.id}` })
  }
  componentDidMount() {
    this.getCompanyData()
  }
  render() {
    const { companyList } = this.state;
    return (
      <View className='Hcompany-wrap'>
        <View className="h-title">装修公司 <View className="more" onClick={this.toPageCompany}>更多<Image className="img" src={require("../../../asset/imgs/right1.png")} /></View></View>
        <View className="gs-list">
          {companyList.map((item) => {
            return (
              <View className="gs-item" key={item.id} onClick={this.toPageCompanyDetail.bind(this, item)}>
                <Image className="img-bg" src={item.url} />
                <View className="c-sub">
                  <Image className="gs-logo" src={item.logo} />
                  <View className="gs-text">
                    <View className="gs-name">{item.name}</View>
                    <View className="gs-num">所有设计：<Text className="num">{item.fasNum}套</Text><Text className="address">{item.dist}</Text></View>
                  </View>
                </View>
              </View>
            )
          })}
        </View>
      </View>
    )
  }
}

export default Hcompany